import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//用来测试设置cookie有效时间后，是否会将cookie存储在客户端的硬盘当中。
public class cookie extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //创建cookie对象
        Cookie cookie1 = new Cookie("username","zhangsan");
        Cookie cookie2 = new Cookie("password","123");

        //设置cookie的有效期，使cookie存储在客户端的硬盘当中
        cookie1.setMaxAge(60*60);
        cookie2.setMaxAge(60*60);

        //将cookie对象发送给客户端浏览器
        response.addCookie(cookie1);
        response.addCookie(cookie2);
    }
}
